home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************
- * *
- * Copyright (c) 1991 Silicon Graphics, Inc. *
- * All Rights Reserved *
- * *
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI *
- * *
- * The copyright notice above does not evidence any actual of intended *
- * publication of such source code, and is an unpublished work by Silicon *
- * Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is *
- * the property of Silicon Graphics, Inc. Any use, duplication or *
- * disclosure not specifically authorized by Silicon Graphics is strictly *
- * prohibited. *
- * *
- * RESTRICTED RIGHTS LEGEND: *
- * *
- * Use, duplication or disclosure by the Government is subject to *
- * restrictions as set forth in subdivision (c)(1)(ii) of the Rights in *
- * Technical Data and Computer Software clause at DFARS 52.227-7013, *
- * and/or in similar or successor clauses in the FAR, DOD or NASA FAR *
- * Supplement. Unpublished - rights reserved under the Copyright Laws of *
- * the United States. Contractor is SILICON GRAPHICS, INC., 2011 N. *
- * Shoreline Blvd., Mountain View, CA 94039-7311 *
- **************************************************************************
- *
- * File: printbox.c
- *
- * Description: Simply instantiates a PrintBox widget.
- *
- **************************************************************************/
-
-
- #ident "$Revision: 1.8 $"
-
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- #include <sys/types.h>
- #include <Xm/Xm.h>
- #include <X11/StringDefs.h>
- #include <Xm/MessageB.h>
- #include <Sgm/PrintBox.h>
-
-
- /* Program globals */
-
- static char *prog_name; /* Program instance name (no path) */
- static char *prog_class = "Printbox"; /* Program class name */
- static Widget top_level; /* Top level widget */
- static Widget print_box; /* printBox widget */
- static Widget error_dialog; /* Error dialog */
- static XtAppContext app_context; /* Application context */
-
-
- /* Replacement error messages */
-
- static char *no_spooler_mess[] = {
- "The print scheduler /usr/lib/lpsched is not running.",
- "Contact your system administrator."
- };
- static int no_spooler_mess_lines = sizeof(no_spooler_mess) / sizeof(char*);
-
-
- /* Help message */
-
- static char *help_mess[] = {
- "'printbox' simply instantiates a PrintBox widget."
- };
- static int help_mess_lines = sizeof(help_mess) / sizeof(char*);
-
- /* Local functions */
-
- static void cancel_cb(Widget, XtPointer, XtPointer);
- static void print_cb(Widget, XtPointer, XtPointer);
- static void error_cb(Widget, XtPointer, XtPointer);
- static void help_cb(Widget, XtPointer, XtPointer);
- static Widget create_error_dialog(void);
- static XmString create_message(char**, int);
- static void manage_error_cb(Widget, XtPointer, XEvent*, Boolean*);
-
-
- /**************************************************************************
- *
- * Function: main
- *
- * Description: Program entry point
- *
- * Parameters:
- * argc (I) - command line argument count
- * argv (I) - command line arguments
- *
- * Return: None
- *
- **************************************************************************/
-
- int main(int argc, char *argv[])
- {
- char *str;
-
- /*
- * Set program instance name
- */
- str = strrchr(*argv, '/');
- prog_name = strdup((str == NULL) ? argv[0]: str + 1);
-
- /*
- * Initialize the X app connection.
- */
- top_level = XtAppInitialize(&app_context, prog_class,
- NULL, 0, &argc, argv, NULL, NULL, 0);
-
- /*
- * Create the PrintBox widget
- */
- print_box = PuiCreatePrintBox(top_level, "printBox", NULL, 0);
- XtManageChild(print_box);
-
- /*
- * Add callbacks
- */
- XtAddCallback(print_box, PuiNcancelCallback, cancel_cb, NULL);
- XtAddCallback(print_box, PuiNhelpCallback, help_cb, NULL);
- XtAddCallback(print_box, PuiNjobInfoCallback, print_cb, NULL);
- XtAddCallback(print_box, PuiNerrorCallback, error_cb, NULL);
- XtAddCallback(print_box, PuiNoptionErrorCallback, error_cb, NULL);
-
- /*
- * Realize all widgets
- */
- XtRealizeWidget(top_level);
-
- /*
- * Start processing events.
- */
- XtAppMainLoop(app_context);
-
- /* NOTREACHED */
- return(1);
- }
-
-
- /*=========================================================================
- LOCAL FUNCTIONS
- =========================================================================*/
-
-
- /**************************************************************************
- *
- * Function: cancel_cb
- *
- * Description: Cancel button exit routine.
- *
- * Parameters:
- * w (I) - invoking widget
- * client_data (I) - client data
- * call_data (I) - standard callback info
- *
- * Return: none
- *
- **************************************************************************/
- /* ARGSUSED */
-
- static void cancel_cb(Widget w, XtPointer client_data, XtPointer call_data)
- {
- exit(0);
- }
-
-
- /**************************************************************************
- *
- * Function: print_cb
- *
- * Description: Print job information callback. This callback is called
- * if a print job has been successfully submitted. The job ID is
- * printed to standard out and the program terminates.
- *
- * Parameters:
- * w (I) - invoking widget
- * client_data (I) - client data
- * call_data (I) - standard callback info
- *
- * Return: none
- *
- **************************************************************************/
- /* ARGSUSED */
-
- static void print_cb(Widget w, XtPointer client_data, XtPointer call_data)
- {
- PuiPrintBoxCallbackStruct *pb_cb = (PuiPrintBoxCallbackStruct*)call_data;
-
- /*
- * Print job ID
- */
- (void)printf("request id is %s\n", pb_cb->job_info->job_id);
-
- exit(0);
- }
-
-
- /**************************************************************************
- *
- * Function: error_cb
- *
- * Description: Handles the display of error messages from the printBox
- * widget.
- *
- * Parameters:
- * w (I) - invoking widget
- * client_data (I) - client data
- * call_data (I) - standard callback info
- *
- * Return: none
- *
- **************************************************************************/
- /* ARGSUSED */
-
- static void error_cb(Widget w, XtPointer client_data, XtPointer call_data)
- {
- XmString str;
- char **err_buf, *estr;
- int num_str;
- PuiPrintBoxCallbackStruct *pb_cb = (PuiPrintBoxCallbackStruct*)call_data;
- Arg arg;
-
- /*
- * If first time, create the error dialog window
- */
- if (!error_dialog)
- error_dialog = create_error_dialog();
-
- /*
- * Determine if this is an option panel error or printbox error
- */
- if (pb_cb->reason == PuiCR_OPT_ERROR) {
- estr = strerror(pb_cb->error_code);
- err_buf = &estr;
- num_str = 1;
- } else {
- /*
- * Select the appropriate message
- */
- switch (pb_cb->error_code) {
- case SL_ERR_SPOOLER_ERROR:
- SLGetSpoolerError(&err_buf, &num_str);
- break;
- case SL_ERR_SPOOLER_UNKNOWN:
- XtAddCallback(error_dialog, XmNokCallback, cancel_cb, NULL);
- err_buf = no_spooler_mess;
- num_str = no_spooler_mess_lines;
- break;
- default:
- estr = SLErrorString(pb_cb->error_code);
- err_buf = &estr;
- num_str = 1;
- break;
- }
- }
-
- /*
- * Set the message in the error dialog
- */
- str = create_message(err_buf, num_str);
- XtSetArg(arg, XmNmessageString, str);
- XtSetValues(error_dialog, &arg, 1);
- XmStringFree(str);
-
- /*
- * Bring up the dialog
- */
- if (XtIsRealized(top_level))
- XtManageChild(error_dialog);
- else
- XtAddEventHandler(top_level, VisibilityChangeMask, False,
- manage_error_cb, NULL);
- }
-
-
- /**************************************************************************
- *
- * Function: manage_error_cb
- *
- * Description: Handles the delayed display of an error dialog. The
- * delay was due to the PrintBox not being visible when the error
- * occurred. We want it visible so that the error dialog is displayed
- * in an appropriate place on the program window.
- *
- * Parameters:
- * w (I) - top level widget
- * client_data (I) - not used
- * event (I) - event that triggered the call
- * cont (I) - continue propagating event flag
- *
- * Return: none
- *
- **************************************************************************/
-
- static void manage_error_cb(Widget w, XtPointer client_data, XEvent *event,
- Boolean *cont)
- {
- XtRemoveEventHandler(top_level, VisibilityChangeMask, False,
- manage_error_cb, NULL);
- XtManageChild(error_dialog);
- }
-
-
- /**************************************************************************
- *
- * Function: help_cb
- *
- * Description: Displays the help message.
- *
- * Parameters:
- * w (I) - invoking widget
- * client_data (I) - not used
- * call_data (I) - not used
- *
- * Return: none
- *
- **************************************************************************/
- /* ARGSUSED */
-
- static void help_cb(Widget w, XtPointer client_data, XtPointer call_data)
- {
- static Widget help_dialog = NULL;
-
- /*
- * If first time, create the help dialog
- */
- if (!help_dialog) {
- Arg wargs[5];
- XmString tstr, mstr;
- register int n;
-
- /*
- * Create title and message strings
- */
- tstr = XmStringCreateSimple("Help");
- mstr = create_message(help_mess, help_mess_lines);
-
- /*
- * Create a dialog
- */
- n = 0;
- XtSetArg(wargs[n], XmNdialogTitle, tstr); n++;
- XtSetArg(wargs[n], XmNmessageString, mstr); n++;
- help_dialog = XmCreateInformationDialog(top_level, "helpDialog",
- wargs, n);
-
- /*
- * Blow off Help and Cancel
- */
- XtUnmanageChild(XmMessageBoxGetChild(help_dialog,
- XmDIALOG_CANCEL_BUTTON));
- XtUnmanageChild(XmMessageBoxGetChild(help_dialog,
- XmDIALOG_HELP_BUTTON));
-
- XmStringFree(tstr);
- XmStringFree(mstr);
- }
-
- /*
- * Display the dialog
- */
- XtManageChild(help_dialog);
- }
-
-
- /**************************************************************************
- *
- * Function: create_error_dialog
- *
- * Description: Creates the error dialog
- *
- * Parameters: none
- *
- * Return: Created dialog widget
- *
- **************************************************************************/
-
- static Widget create_error_dialog()
- {
- Widget dialog;
- Arg wargs[5];
- XmString tstr;
- register int n;
-
- /*
- * Create some compound strings
- */
- tstr = XmStringCreateSimple("Error"); /* Dialog window title */
-
- /*
- * Create a modal dialog
- */
- n = 0;
- XtSetArg(wargs[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++;
- XtSetArg(wargs[n], XmNdialogTitle, tstr); n++;
- dialog = XmCreateErrorDialog(top_level, "errorDialog", wargs, n);
-
- /*
- * Blow off Help and Cancel
- */
- XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
- XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
-
- XmStringFree(tstr);
-
- return dialog;
- }
-
-
- /**************************************************************************
- *
- * Function: create_message
- *
- * Description: A utility function to create a compound string message from
- * a multi-element array of strings.
- *
- * Parameters:
- * str_array (I) - array of message strings.
- * num_str (I) - number of strings in array.
- *
- * Return: A compound string.
- *
- **************************************************************************/
-
- static XmString create_message(char **str_array, int num_str)
- {
- XmString xm_newstr, xtemp, xmstr;
- register char *str;
- register int i;
-
- xmstr = XmStringCreateSimple("");
- for (i = 0, str = *str_array; i < num_str; str = *++str_array, i++) {
- if (i) {
- xm_newstr = XmStringSeparatorCreate();
- xtemp = xmstr;
- xmstr = XmStringConcat(xtemp, xm_newstr);
- XmStringFree(xtemp);
- XmStringFree(xm_newstr);
- }
- xm_newstr = XmStringCreateSimple(str);
- xtemp = xmstr;
- xmstr = XmStringConcat(xtemp, xm_newstr);
- XmStringFree(xtemp);
- XmStringFree(xm_newstr);
- }
-
- return xmstr;
- }
-
-